<?php  if( !defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('get_width'))
{
	function get_width($full_path)
	{
		$size = @getimagesize($full_path);

		return ($size[0]);
	}
}

if ( ! function_exists('get_height'))
{
	function get_height($full_path)
	{
		$size = @getimagesize($full_path);

		return ($size[1]);
	}
}

if ( ! function_exists('get_size_percentage'))
{
	function get_size_percentage($full_path, $scale)
	{
		$size = @getimagesize($full_path);

		return ($size[0] <= $scale) ? 100: ($scale/$size[0]) * 100;
	}
}

if ( ! function_exists('resize_image')) 
{
    # display large image
	function resize_image($img, $h = NULL, $w = NULL, $percent = 0, $constrain = 1, $style = FALSE) {

		// get image size of img
		$x = @getimagesize($img);
		// image width
		$sw = $x[0];
		// image height
		$sh = $x[1];

		if ($percent > 0) {
			// calculate resized height and width if percent is defined
			$percent = $percent * 0.01;
			$w = $sw * $percent;
			$h = $sh * $percent;
		} else {
			if (isset ($w) AND !isset ($h)) {
				// autocompute height if only width is set
				$h = (100 / ($sw / $w)) * .01;
				$h = @round ($sh * $h);
			} elseif (isset ($h) AND !isset ($w)) {
				// autocompute width if only height is set
				$w = (100 / ($sh / $h)) * .01;
				$w = @round ($sw * $w);
			//} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
			} elseif (isset ($h) AND isset ($w)) {
				// get the smaller resulting image dimension if both height
				// and width are set and $constrain is also set
				$hx = (100 / ($sw / $w)) * .01;
				$hx = @round ($sh * $hx);

				$wx = (100 / ($sh / $h)) * .01;
				$wx = @round ($sw * $wx);

				if ($hx < $h) {
					$h = (100 / ($sw / $w)) * .01;
					$h = @round ($sh * $h);
				} else {
					$w = (100 / ($sh / $h)) * .01;
					$w = @round ($sw * $w);
				}
			}
		}
                
		return ($style) ? "height: ".$h."px; width: ".$w."px" : "height=\"$h\" width=\"$w\"";

	}
}


/* End of file image_detail_helper.php */
/* Location: ./system/application/helpers/image_detail_helper.php */
